package edu.gatech.aristotle.random.util;

import java.io.BufferedReader;
import java.util.ArrayList;

import net.util.File_Handler;

public class Util_FormatHandler {
	/**
	 * 
	 * @param randomSubset: an arraylist of integers with value 1 or 0.
	 * @return the sum of the integers.
	 */
	static public int sumIntegerList( ArrayList<Integer> randomSubset ){
		int sum	= 0;
		
		for ( int i : randomSubset ){
			sum += i;
		}
		
		return sum;
	}
	
	static public ArrayList<Integer> oneStringToInteger( String lineContent ){
		ArrayList<Integer> integers	= new ArrayList<Integer>();
		
		//Debug.println( "oneStringToInteger: " + lineContent );
		
		for (int i = 0; i < lineContent.length(); i++ ){
			char c = lineContent.charAt( i );
			integers.add( new Integer( c + "" ) );
		}
		
		return integers;
	}
	
	static public ArrayList<Integer> retriveOneLineIntegers( String matrixFileName, int line ){
		String lineContent = null;
		try {	
			BufferedReader bufferReader = File_Handler.createBufferReader( matrixFileName );
			for ( int i = 0; i < line - 1; i++ ){
				bufferReader.readLine();
			}
			
			lineContent = bufferReader.readLine().trim();			
		}catch( Exception e ){
			System.err.print( "write new format: " + e );
		}		
//		ArrayList<Integer> integers	= new ArrayList<Integer>();
//		
//		for (int i = 0; i < lineContent.length(); i++ ){
//			char c = lineContent.charAt( i );
//			integers.add( new Integer( c + "" ) );
//		}
		
		return oneStringToInteger( lineContent );
	}
}
